package cate.game.activity.merge;

import cate.common.table.d.GDOperation;
import cate.common.table.d.GDParamTool;
import cate.game.activity.merge.msg.MergeActBaseInfoResp;
import cate.game.res.MixRes;
import cate.game.res.MixResAdder;
import cate.game.role.RoleDependent;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;
import easy.java.practice.errorcode.EcResult;

@NoteClass("合服活动总览")
public class MergeActOverall extends RoleDependent {
    @NoteField("上次合服奖励领取时间")
    public long lastMergeRewardGetTime;

    /**
     * 发送消息到前端
     */
    public void noticeUpdate() {
        role.sendNow(new MergeActBaseInfoResp(role.getGame().config.getMergeTime(), lastMergeRewardGetTime));
    }

    /**
     * 领取合服一次性奖励
     *
     * @return 领取结果
     */
    public EcResult<Void> onGetMergeReward() {
        EcResult<Void> r = new EcResult<>();
        if (lastMergeRewardGetTime >= role.getGame().config.getMergeTime()) {
            return r.fail("没有可领取奖励");
        }
        MixRes reward = new MixRes(GDParamTool.getString(role.getGame().table.common.param, 5006, ""));
        if (reward.isEmpty()) {
            return r.fail("没有奖励");
        }
        lastMergeRewardGetTime = role.getGame().config.getMergeTime();
        new MixResAdder().setRes(reward)
                .setDialogReward(true)
                .setSendMailWhenFull(true)
                .setOperation(GDOperation.MERGE_ONCE_REWARD)
                .exe(role);
        return r.success();
    }
}
